package com.grace.cms.general.controller.api;

import com.grace.common.core.controller.BaseController;
import com.grace.common.core.domain.AjaxResult;
import com.grace.cms.general.taglib.LinkTag;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/{themeName}/api/link")
public class LinkApiController extends BaseController {

  @Autowired
  private LinkTag linkService;

  /**
   * 综合查询
   * 
   * @param cmsLink
   * @return
   */
  @GetMapping("/list/{parentId}/{nodeType}")
  public AjaxResult list(@PathVariable(value = "themeName") String themeName, @PathVariable("parentId") Long parentId, @PathVariable("nodeType") String nodeType) {

    return AjaxResult.success(linkService.listLinks(parentId, nodeType));
  }

  /**
   * 获取链接列表
   * 
   * @param groupName
   * @return
   */
  @GetMapping("/tree/{parentId}/{nodeType}")
  public AjaxResult listLinkByKey(@PathVariable(value = "themeName") String themeName, @PathVariable("parentId") Long parentId, @PathVariable("nodeType") String nodeType) {
    return AjaxResult.success(linkService.linkTree(parentId, nodeType));
  }

  /**
   * 获取链接通过ID
   * 
   * @param linkId
   * @return
   */
  @GetMapping("/get/{linkId}")
  public AjaxResult getLinkById(@PathVariable(value = "themeName") String themeName, @PathVariable("linkId") Long linkId) {
    return AjaxResult.success(linkService.selectCmsLinkById(linkId));
  }

}
